"""
用于模型的解释性分析的工具包，提供统一的解释接口。
"""


class BasicExplaintation:
    support_explain_type = []

    def __init__(self, **kwargs):
        for k, v in kwargs.items():
            assert k not in self.support_explain_type, "不支持的解释条目，" + k
        self.kwargs = kwargs
        self.items = list()

    def to_dict(self):
        return self.kwargs

    def __repr__(self):
        return repr(self.items)


class LMExplaintation(BasicExplaintation):

    def __init__(self, **kwargs):
        # BasicExplaintation.support_explain_type.extend(["sentence_pro", "token_pro"])
        BasicExplaintation.__init__(self, **kwargs)
        for k, v in kwargs.items():
            if k == "sentence_pro":
                self.items.append({
                    "name": k,
                    "type": "float",
                    "introduction": "生成整个句子的概率。",
                    "value": v
                })
            if k == "token_pro":
                self.items.append({
                    "name": k,
                    "type": "List[Tuple[str, float]]",
                    "introduction": "生成的整个句子中，每个token的概率。",
                    "value": v
                })
